package com.kc.demo.kcapidemo.config;

import com.kc.demo.kcapidemo.demo.CustomizedWebSocketClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.URI;
import java.net.URISyntaxException;

/**
 * WebSocket客户端配置类
 */
@Configuration
public class WebSocketClientConfig {

    /**
     * socket连接地址
     */
    private static String webSocketUri = "ws://127.0.0.1:8080/WebDemo//323232";

    /**
     * 注入Socket客户端
     *
     * @return
     */
    @Bean
    public CustomizedWebSocketClient initWebSocketClient() {

        URI uri = null;
        try {
            uri = new URI(webSocketUri);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        CustomizedWebSocketClient webSocketClient = new CustomizedWebSocketClient(uri);
        //启动时创建客户端连接
        webSocketClient.connect();
        return webSocketClient;
    }


}